//
//  SetLocationsResponse.h
//  NetMobileLocation
//
//  Created by Mehmet Sinan Şahin on 1/29/12.
//  Copyright (c) 2012 netgis. All rights reserved.
//

#include "Command.h"
#include "NGUtility.h"

@class SoapFault;

@interface TransactionResult : NSObject {
    NSString * inserted;
    NSString * updated;
    NSString * deleted;
    NSString * status;
}
@property (nonatomic, retain) NSString *inserted;
@property (nonatomic, retain) NSString *updated;
@property (nonatomic, retain) NSString *deleted;
@property (nonatomic, retain) NSString *status;

- (id) init:(NSString *)pInserted updated:(NSString *)pUpdated deleted:(NSString *)pDeleted status:(NSString *)pStatus;
- (id) init;
- (BOOL) isSuccessful;
- (NSString *) description;
@end

@interface TransactionResponse : NSObject {
    NSMutableArray * results;
}
@property (nonatomic, retain) NSMutableArray *results;

- (id) init;
- (void) add:(TransactionResult *)result;
- (TransactionResult *) last;
- (NSString *) description;
@end

@interface PutInfoExResult : NSObject {
    NSMutableArray * responses;
}
@property (nonatomic, retain) NSMutableArray *responses;


- (id) init;
- (void) add:(TransactionResponse *)response;
- (TransactionResponse *) last;
- (NSString *) description;
@end

@interface Command : NSObject {

    CommandEnum _command;
    NSString* value;
}
@property (nonatomic, assign) CommandEnum _command;
@property (nonatomic, retain) NSString *value;

/*
 * Usage status in ios device
 */
- (BOOL) isUsedForDevice;
@end

@interface Message : NSObject {
    int _id; //for database, afterwards deletion by id
    NSString *Sender;
    NSString *Time;
    //NSString *Type;
    //NSString *MessageHeader;
    //NSString *MessageBody;
    NSString *Command;
    NSString *CommandParameter;
    BOOL read;
}
@property (nonatomic, retain) NSString *Sender;
@property (nonatomic, retain) NSString *Time;
//@property (nonatomic, retain) NSString *Type;
//@property (nonatomic, retain) NSString *MessageHeader;
//@property (nonatomic, retain) NSString *MessageBody;
@property (nonatomic, retain) NSString *Command;
@property (nonatomic, retain) NSString *CommandParameter;
@property int _id;
@property (nonatomic, assign) BOOL read;

- (Command *)getOutCommand;
- (NSString *) getMessageBody;
- (NSString *) getMessageHeader;
- (NSString *)viewMessageBody;
- (NSString *)viewMessageHeader;
- (MESSAGE_TYPE) getType;
- (BOOL) isCommand;
- (BOOL) isMessage;
- (void) setReadStatus: (int) status; //1:true else false

@end

@interface DataRetrievingServiceResult : NSObject {
    NSString * IsUnknownDevice;
    NSString * HasMessage;
    NSMutableArray *messages;
    NSMutableArray * putInfoExResults;
}
@property (nonatomic, retain) NSMutableArray *putInfoExResults;
@property (nonatomic, retain) NSString *IsUnknownDevice;
@property (nonatomic, retain) NSString *HasMessage;
@property (nonatomic, retain) NSMutableArray *messages;

- (id) init;
- (void) add:(PutInfoExResult *)result;
- (void) addMessage: (Message *)message;
- (PutInfoExResult *) last;
- (NSString *) description;
@end

@interface DataRetrievingServiceResults : NSObject {
    NSMutableArray * results;
}

- (id) init;
- (BOOL) isSuccessful;
- (void) add:(DataRetrievingServiceResult *)result;
- (DataRetrievingServiceResult *) last;
- (NSString *) description;
- (NSMutableArray *) getMessages;
- (NSMutableArray *) getCommands;
@end


/**
 * 
 * @author NetGis
 * 
 */

extern NSString * TAG_NAME_INSERTED;
extern NSString * TAG_NAME_UPDATED;
extern NSString * TAG_NAME_DELETED;
extern NSString * TAG_NAME_STATUS;
extern NSString * TEST_XML_SUCCESS_SETLOCATIONS;
extern NSString * TEST_XML_SUCCESS_SETLOCATION;
extern NSString * TAG_NAME_STATUS_SUCCESS;
extern NSString * TAG_NAME_IS_KNOWN_DEVICE;
extern NSString * TAG_NAME_MESSAGES;
extern NSString * EX_INVALID_SESSIONID;


@interface SetLocationsResponse : NSObject {
    NSString * responseXml;
    DataRetrievingServiceResults * results;
    NSString * errorString;
    SoapFault * soapFault;
    NSError * error;
    NSString *strErrorCode;
    BOOL test;
}

@property(nonatomic, retain) NSError * error;
@property(nonatomic, retain) NSString * errorString;
@property(nonatomic, retain, readonly) SoapFault *soapFault;
@property(nonatomic, readonly) BOOL successful;
@property(nonatomic, retain) NSString * responseXml;
@property(nonatomic, retain) DataRetrievingServiceResults * results;
@property(nonatomic, assign) NSString *strErrorCode;
@property(nonatomic, assign) BOOL test;

- (id) initWithError:(NSError *)err;
- (id) initWithSoapFault:(SoapFault *)fault;
- (id) initWithResponseXml:(NSString *)responseXml;
- (NSString *) description;
- (BOOL) isSuccessful;
- (BOOL) hasException;

/* if response has exception of EX_INVALID_SESSIONID, needRelogin must be return true */
- (BOOL) needRelogin;
- (NSMutableArray *) getMessages;
- (NSMutableArray *) getCommands;

- (void) parse;
- (void) processCommands;

+ (SetLocationsResponse *) test;

@end

